package lab6.systemCustom;

import java.util.ArrayList;
import java.util.StringTokenizer;

@SuppressWarnings("unchecked")
public class ListStudentsRegisteredHandler extends CommandEventHandler {

	public ListStudentsRegisteredHandler(DataBase objDataBase, int iCommandEvCode, int iOutputEvCode) {
		super(objDataBase, iCommandEvCode, iOutputEvCode);
	}

	protected String execute(String param) {
		StringTokenizer objTokenizer = new StringTokenizer(param);
		String sCID = objTokenizer.nextToken();

		Course objCourse = this.objDataBase.getCourseRecord(sCID);
		if (objCourse == null) {
			return "Id curs inexistent";
		}
		ArrayList vStudent = objCourse.getRegisteredStudents();

		String sReturn = "";
		for (int i = 0; i < vStudent.size(); i++) {
			sReturn += (i == 0 ? "" : "\n") + ((Student) vStudent.get(i)).toString();
		}
		return sReturn;
	}

}